asp.net-mvc-5

How do I change the url in MVC 5?

夙愿已清 提交于 2019-12-08 01:34:21
问题 I am trying to change a URL in MVC 5 from "Master" to "Master-Franchise" & I thought the following would work but the URL is still just "Master". // GET: Master-Fanchise [Route("Master-Fanchise")] public ActionResult Master() { return View(); } 回答1: Use ActionName attributes which allows you to give action name for controller method regardless of method name. [ActionName("Master-Fanchise")] public ActionResult Master() { return View(); } 回答2: Have you enabled attribute routing as it is not

Decimal symbol issue in MVC, C#?

旧街凉风 提交于 2019-12-08 00:51:33
问题 I'm using MVC 5.0 I set the culture in config: <system.web> <globalization uiCulture="fa-IR" culture="fa-IR" /> </system.web> I have a model as the following: public class MyModel { [DisplayName("NbatPersent")] [Range(0, 100)] public double NbatPersent{ get; set; } } MVC shows the NbatPersent value in View like 22/5 and when I wanna submit form the form validator alert me The field NbatPersent must be a number. . It can't convert 22/5 to 22.5 It will be OK if I enter 22.5 but if the property

Using Postal and Hangfire in Subsite

吃可爱长大的小学妹 提交于 2019-12-07 23:44:37
问题 I have been trying to use Postal on my MVC5 site. When I host my webpage a subsite ie, http://localhost/Subsite I am receiving the error The virtual path '/' maps to another application, which is not allowed I have debugged it down to when the ControllerContext is being created the HttpContext isn't getting set correctly. Since I'm running Postal from Hangfire the HttpContext.Current is always null. Postal creates the ContollerContext using the code below. ControllerContext

Combine my ApplicationsDbContext with IdentityDbContext no key defined using MVC 5

心已入冬 提交于 2019-12-07 22:53:57
问题 I was combining my existing DBContext with the new IdentityDbContext in MVC 5. I managed to combine the two contexts but when I ran my application and the model was being created I was presented with the following error message: Context.IdentityUserLogin: : EntityType 'IdentityUserLogin' has no key defined. Define the key for this EntityType. Context.IdentityUserRole: : EntityType 'IdentityUserRole' has no key defined. Define the key for this EntityType. 回答1: I worked out how to fix it after

Verify User Permission on Action Filter or Authroize Filter?

让人想犯罪 __ 提交于 2019-12-07 22:41:16
问题 I am developing a website in MVC4. I developed user roles and permissions. I want to ask where I should check user permission access: in the Custom Action filter, or the Custom Authorization filter? If user does not have access to the module, then I must show a toaster error message. How do I show this message in an action filter? 回答1: I use to write custom action filter attribute so that on the action call this method is called and i check in it if user role allows him to call this action or

Fallback route for MVC Areas

假如想象 提交于 2019-12-07 21:47:07
问题 Using asp.net core MVC application here. I have my areas defined and routing works as expected. One thing i would like to do, is have a fallback route in case the area does not exist. I have the following structure: APP -- Areas -- SharedArea -- Controllers -- LoginController -- UserController -- AnotherController -- AndSoOnController -- SomeArea1 -- Controllers -- HomeController -- SomeArea2 -- Controllers -- HomeController -- LoginController My ultimate goal, is to have shared controllers

Infinite re-direct loop after AAD Authentication when redirect is specified

你说的曾经没有我的故事 提交于 2019-12-07 20:09:09
问题 If I specify a redirect URI in my OpenIdConnectAuthenticationOptions like so app.UseOpenIdConnectAuthentication( new OpenIdConnectAuthenticationOptions { ClientId = clientId, Authority = Authority, PostLogoutRedirectUri = postLogoutRedirectUri, RedirectUri = redirectUri, Notifications = new OpenIdConnectAuthenticationNotifications() { AuthenticationFailed = context => { context.HandleResponse(); context.Response.Redirect("/Error?message=" + context.Exception.Message); return Task.FromResult(0

How to delete user with UserManager in mvc5

不想你离开。 提交于 2019-12-07 19:51:22
问题 I'm using mvc5, and everything about user account management I do with UserManager. It works good with roles, claims, etc. But I didn't find how to delete user with UserManager. Is there a way to delete user with UserManager? I can create Database context with dbset and then delete it from this context, but I don't want create dbcontext, userclass, etc. for one delete method. 回答1: Delete was not supported in UserManager in 1.0, but its supported in the upcoming 2.0 release, and in the current

User.Identity.Name - which assembly reference brings that into your project?

那年仲夏 提交于 2019-12-07 19:49:38
问题 I can't find out which reference assembly the User.Identity.Name comes from. How do I find that out? I need to add it to a class library rather than the default MVC 5 app I have made so that I can have access to it? http://msdn.microsoft.com/en-us/library/system.web.httpcontext.user(v=vs.110).aspx C# Class Library / AUser.cs public class AUser { public string Username { get { return User.Identity.Name // doesn't notice User } } } 回答1: Appears to be in the System.Web namespace. http://msdn

MVC 5 + $Post() function not working after hosted on server

跟風遠走 提交于 2019-12-07 19:47:59
问题 I have developed an application in MVC5. Onclick of a link on the View below code gets invoked - // Code in View File $.post('../ControllerName/FunctionName', //this is your url { id: image, }, function (data) { alert("Successfully published"); } ).error(function () { alert("Failed to publish"); }); //Code in Controller [HttpPost] public void ISPPDF(string id) {} Issue that i am facing is the ISPPDF() function gets invoked when i run it through visual studio.However after i hosted my