|
|
Thanks will try it out. most of the things explained there, I did try. But let me verify it well and get back. thanks.
|
|
|
|
|
This is a quality of life issue I've been researching. For certain controllers I would like to add a static method or property that will contain it's absolute URL so I can make redirects a little cleaner but I cannot figure out an elegant solution.
For instance
return RedirectToRoute("Index", "Home");
return RedirectToRoute(Controllers.HomeController.DefaultRedirect); Is this possible?
I've been looking at routing but all the documentation that I find is limited to top layer functionality. Additionally, everything I find requires a RequestContext , a ControllerContext , or some other object that can only be known from within the controller during a web request.
One thing that I am not liking about MVC is having the code behind peppered with string literals all pointing to different controllers and actions. I like to be able to rename the Index controller to Index2 without having to hunt down 45 different places that reference the URL. Not to mention all of the other controllers that might have an Index action that just make it more difficult to find.
if (Object.DividedByZero == true) { Universe.Implode(); }
|
|
|
|
|
|
I did see that one during my searching but since it is called from within a controller, it doesn't really help me since I am looking for a static method in a controller that will generate a correct Url all the time. I did find a way to do it but it still isn't elegant as it does not provide the absolute Url like I would like.
[MyAuthorizationFilter]
public class HomeController : Controller
{
public static string GetDefaultRedirectUrl(RequestContext context)
{
var routeValues = new RouteValueDictionary();
routeValues.Add("area", "somearea");
routeValues.Add("controller", "Home");
routeValeus.Add("action", "Index");
var urlHelper = new UrlHelper(context);
string url = urlHelper.RouteUrl(routeValues);
}
} I'm still debugging my code due to tearing it apart and rewriting it dozen times trying to figure this out. I has worked but I have to fix other things before I can see if it works for what I intend it to do.
if (Object.DividedByZero == true) { Universe.Implode(); }
|
|
|
|
|
Controllers don't have urls, that is why you are struggling to do this.
What'a the URL for this action?
public class HomeController : Controller
{
public ActionResult Index(int? id)
{
}
}
Is it /Home/Index/1? Is it /MyUrl/Index/1/Home?
The answer is both of them.
routes.MapRoute(
name: "Test",
url: "MyUrl/{action}/{id}/{controller}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
|
|
|
|
|
I was assuming that if the application can deduce which controller and action to route an http request to when a request is received that the reverse was also possible. I guess that it isn't possible after all.
It would appear that a controller cannot know where it's located in the website hierarchy until after it's called. Since the default routing basically follows the file system and/or namespaces I thought that there might be a way provided to backtrack up the structure to get a controller's absolute URL at runtime.
Sigh, back to peppering my controller and filter code with string literals.
if (Object.DividedByZero == true) { Universe.Implode(); }
|
|
|
|
|
How to Combine simple form and grid CRUD operations in single view and also post the user entered data in single submit button clicked ?
|
|
|
|
|
Good day,
as the subject suggest i would like to ask the community or atleast point em in the right direction .. i am afraid im lost within the google walls of search engine.. in fact i have 3
listed below( and some follow up question as soon as these are answered):
1) can i implement ADFS(Active Directory Federation Service) log in to an existing asp.net website?
2) would i need to re do the website to implement it?
3) do i need to use any plug ins, or is there any direct way of doing that?
im sorry for being blunt... im a beginner in web and asp.net i only created a basic website... and our system admin ask me to connect it to our Active Directory as part of our company policy
thanks in advance!
|
|
|
|
|
how to display an Image In View..?
|
|
|
|
|
By using the <img> tag, just as you would in any HTML document:
HTML img tag[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
public IHttpActionResult Post([FromBody] product Products)
{
...
}
public IHttpActionResult Post([FromBody] List<product> Products)
{
...
}
when I used List<product> I got empty products. How to handle it?
|
|
|
|
|
Can you update your question with code where you are posting the data?
"It is easy to decipher extraterrestrial signals after deciphering Javascript and VB6 themselves.", ISanti[ ^]
|
|
|
|
|
|
Hi Friends
I have sub level hyperlink in usercontrol page, with separate css class getting called in this user control, but not sure why the sub level hyperlink is not showing when hovering on main hyperlink. Please help, is there any changes with web.config will affect this.
@ control language="C#" autoeventwireup="true" inherits="GUI_UserControl_ImmiMenu, App_Web_aau350gx" %>
<link href="../../Includes/Styles/ImmMenu.css"rel="stylesheet" type="text/css" />
<?xml version="1.0" encoding="UTF-8"?>
<div id="navigation">
<ul class="top-level">
<li><asp:HyperLink ID="HyperLink3" runat="server">WorkPermit</asp:HyperLink>
<ul class="sub-level">
<li><asp:HyperLink ID="HyperLink13" runat="server" NavigateUrl="~/GUI/Visadept/ImmFirstLook.aspx" >Pending Cases</asp:HyperLink></li>
<li><asp:HyperLink ID="HyperLink14" runat="server" NavigateUrl="~/GUI/Visadept/WorkPermitStatus.aspx" >Status</asp:HyperLink></li>
<li><asp:HyperLink ID="HyperLink15" runat="server" NavigateUrl="~/GUI/Visadept/Reports.aspx" >Report</asp:HyperLink></li>
</ul>
</li>
</ul>
</div>
Please help, this is very urgent, Thanks in advance
Regards
Priya
|
|
|
|
|
Is this some third party menu control you are using? If yes, do you have all required CSS and JS files included in the page?
"It is easy to decipher extraterrestrial signals after deciphering Javascript and VB6 themselves.", ISanti[ ^]
|
|
|
|
|
Thanks lot for reply, no I am not using 3rd party, all the related css and js files are available, and surprisingly the same set of published code is working fine, but only in some servers I am facing this issue, I doubt this is something with web.config changes I have added, but tried to compare working version vs current version, but not helping.
|
|
|
|
|
You can perhaps check in Developer Options -> Console if there are any specific errors when you access application from those servers.
"It is easy to decipher extraterrestrial signals after deciphering Javascript and VB6 themselves.", ISanti[ ^]
|
|
|
|
|
Dear Team,
I am using Azure webapps to publish my ERP software . NOw i need to publish new updates to all / more than one webapp from visual studio 2017 in single publish. Because its very difficulties to publish each updates to server one by one .
Kindly help me to create a solution to upload updates to all clients in single click
Thank you
Dominic Louis
|
|
|
|
|
I thought I could do this in one sweep off the states seed.
But I keep getting 0 in the Countries states .
As a refresher:
public class WEBSITE_COUNTRIES
{
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public ObjectId Id { get; set; }
public string DisplayId { get; set; }
public string LongName { get; set; }
public string ShortName { get; set; }
public bool Enabled { get; set; }
public List<WEBSITE_STATES> States { get; set; }
}
So I have a country collection that I grabbed to read data from called websiteCountries
I figured I could use the same collection to write to as well, maybe I'm wrong.
So I grabbed the country collection for US, then all the States for US, 56 of them.
I just can't get a write to US-States[].
At first try, I had no states: [], so I went back to countries and added a blank states[].
ObjectId US_VI_Id = ObjectId.GenerateNewId();
var state_VI = new WEBSITE_STATES() { Id = US_VI_Id, DisplayId = US_VI_Id.ToString(), CountryId = country.DisplayId, CountryCode = country.ShortName, LongName = "Virgin Islands", ShortName = "VI", Enabled = true }
await websiteStates.InsertOneAsync(state_VI);
WEBSITE_COUNTRIES country_US = await websiteCountries.Find(c => c.ShortName == country.ShortName).FirstOrDefaultAsync();
ICollection<WEBSITE_STATES> states_US = await websiteStates.FindSync(c => c.CountryCode == country.ShortName).ToListAsync();
and I always get this.
{
"_id" : ObjectId("5b8080730cf709469424b9e2"),
"DisplayId" : "5b8080730cf709469424b9e2",
"LongName" : "United States",
"ShortName" : "US",
"Enabled" : true,
"States" : []
}
Maybe I'm suppose to InsertOneAsync(entire state record); that's all that I can think of at the moment.
Anyways, it's Friday, going home to wash the car and get ready for bowling, easy things to accomplish.
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
It's been pretty rough trying to figure out how to write the MongoDB context and some sort of MongoInitializer that runs from Programs.cs while passing the settings to load the MongoDB parameters. I'm seeding in .Net Core and not Angular V6 because it just seems like the right place to do it.
So I've seeded my default users, countries, and now states / provinces. I decided to copy the format of my previous versions here, but was forced to really change it up MongoDB style. I'm trying to loop through the countries I just wrote, to create states.
So this is what I wrote based off research from the internet. Don't know if it's right or wrong and it's very foreign to me. I'm in uncharted waters here on this. I understand this:
var websiteCountries = _database.GetCollection<WEBSITE_COUNTRIES>("Website_Countries");
but not the cursor part:
using (IAsyncCursor<WEBSITE_COUNTRIES> cursor = await websiteCountries.FindAsync(new BsonDocument()))
So the above code must set the cursor position; perhaps it set it at the end, and that's why the batch is null.
I'm not even sure if I'm on the right track here. I really don't care if it's async or not.
I'll read up on this part here await websiteCountries.FindAsync(new BsonDocument())
public static async Task SeedAsync(IMongoDatabase _database)
{
var websiteStates = _database.GetCollection<WEBSITE_STATES>("Website_States");
double totalDocuments = websiteStates.CountDocuments(FilterDefinition<WEBSITE_STATES>.Empty);
if (totalDocuments == 0)
{
var websiteCountries = _database.GetCollection<WEBSITE_COUNTRIES>("Website_Countries");
try
{
using (IAsyncCursor<WEBSITE_COUNTRIES> cursor = await websiteCountries.FindAsync(new BsonDocument()))
{
IEnumerable<WEBSITE_COUNTRIES> batch = cursor.Current;
foreach (WEBSITE_COUNTRIES country in batch)
{
Console.WriteLine(country.LongName);
}
}
}
catch(Exception ex)
{
Console.WriteLine(ex.Message.ToString());
}
}
}
I wrote this, well sort of copied it, havn't tested it yet. This is in my UserRespository and according to documentation is a CRUD method of getting all the users. What's sort of confusing is the context. I can generate a context here in the repository, but had to use a manual connection in my Seed. Perhaps this is the answer to my problem. FindSync vs FindAsync(_ => true).ToListAsync() . Why true?
public class UserRepository : IUserRepository
{
private readonly MongoDBContext _context = null;
public UserRepository(IOptions<Settings> settings)
{
_context = new MongoDBContext(settings);
}
public async Task<IEnumerable<WEBSITE_USERS>> GetAllUsers()
{
try
{
return await _context.WebsiteUsers
.FindSync(_ => true).ToListAsync();
}
catch (Exception ex)
{
throw ex;
}
}
My MongoDBInitializer where I wasn't able to generate a context. This isn't that important but it did send me down a different road and how I ended up here on this path.
public static void SeedData(Settings settings)
{
IMongoDatabase _database = null;
var client = new MongoClient(settings.MongoDB.Connection);
if (client != null)
_database = client.GetDatabase(settings.MongoDB.Database);
WebsiteUsers.Seed(_database);
var countryTask = WebsiteCountries.Seed(_database);
var statesTask = WebsiteStates.SeedAsync(_database);
}
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
I have a states collection now in MongoDB
I sort of get it now. _ => true must be a wildcard like * , generate a list of countries , as a Result , now I can do the old school loop, which I needed in case I had to walk the code. There was .ForEach(country => { // do work } which did a single execution that may be more efficient.
Ended up with this ...
public static async Task SeedAsync(IMongoDatabase _database)
{
var websiteStates = _database.GetCollection<WEBSITE_STATES>("Website_States");
double totalDocuments = websiteStates.CountDocuments(FilterDefinition<WEBSITE_STATES>.Empty);
if (totalDocuments == 0)
{
var websiteCountries = _database.GetCollection<WEBSITE_COUNTRIES>("Website_Countries");
try
{<br />
foreach (var country in websiteCountries.FindSync(_ => true).ToListAsync().Result)
{
switch (country.ShortName)
{
case "US":
ObjectId US_AL_Id = ObjectId.GenerateNewId();
var state_AL = new WEBSITE_STATES() { Id = US_AL_Id, DisplayId = US_AL_Id.ToString(), CountryId = country.DisplayId, CountryCode = country.ShortName, LongName = "Alabama", ShortName = "AL", Enabled = true };
await websiteStates.InsertOneAsync(state_AL);
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
It was about updating the country collection, and not inserting.
Guess there are two ways to work with MongoDB, one being through a context using the driver, and the other working with the MongoDB .Net Core driver straight.
This is where I got confused. So I'm using my MongoDBContext in my repositories which are CRUD and just the driver in my services which are REST.
Anyways, this is just a learning exercise for later use. I'll dump it and replace it with a text file written in the same BSON format later down the road.
But at least I got this working for now, well I haven't consumed yet so I'll find out.
var filter_US = Builders<WEBSITE_COUNTRIES>.Filter.Eq(s => s.ShortName, country.ShortName.ToUpper());
var update_US = Builders<WEBSITE_COUNTRIES>.Update.Set(s => s.States, states_US);
await websiteCountries.UpdateOneAsync(filter_US, update_US);
And my result, I saw Arizona is wrong, fixed.
{
"_id" : ObjectId("5b8434defb1e6524f8cc0554"),
"DisplayId" : "5b8434defb1e6524f8cc0554",
"LongName" : "United States",
"ShortName" : "US",
"States" : [
{
"_id" : ObjectId("5b8434dffb1e6524f8cc0582"),
"Name" : "Alabama",
"Abbr" : "AL"
},
{
"_id" : ObjectId("5b8434dffb1e6524f8cc0583"),
"Name" : "Alaska",
"Abbr" : "AK"
},
{
"_id" : ObjectId("5b8434dffb1e6524f8cc0583"),
"Name" : "Arizona",
"Abbr" : "AZ"
},
{
"_id" : ObjectId("5b8434dffb1e6524f8cc0585"),
"Name" : "Arkansas",
"Abbr" : "AR"
},
On a side not about my Angular V6 .Net Core 2.1 training exercise:
I finally got all my folders and files organized efficiently. Basically modules, components and services in Angular, plus my routing with lazy loading is correct. Figured out how to change navbars and footers using *ngIf. Got my new Auth Guard authentication working in Angular, including the Auth0 token and wrote a REST service in .Net Core to handle it, with cookies and token generation. My ContactUs works with my CRUD Repository, just have to write the email part, and figure out if I should do it in .Net Core, Angular or write something in NodeJS for it. Perhaps a .Net console app. So now I can move forward with more head scratchers and frustration. What I have learned so far is that Angular V6 is one thing and .Net Core is a whole different beast, but sort of the same. It's really hard to integrate or write and learn the two together. I can see learning Angular V6 first, and then dropping it into .Net Core and hooking it up being a better path to take. But then you have to architect your.Net Core 2 project in order to pull that off, and can't really rely on a template.
I'm pretty sure I have the terminology correct here. If I'm wrong feel free to correct me so I can get it right.
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
I have following code in ASP.NET MVC5 custom helper need to be converted in ASP.NET Core MVC custom helper:
UrlHelper url = new UrlHelper(HttpContext.Current.Request.RequestContext);
string urlEdit = url.RouteUrl("Default");
I have read Microsoft doc about how to access HttpContext in ASP.NET Core but still cannot figure it out how to convert the above code.
-- modified 22-Aug-18 12:43pm.
|
|
|
|
|