asp.net-mvc-5

ASP.NET MVC Overriding Index action with optional parameter

跟風遠走 提交于 2019-12-10 11:25:51
问题 I want to accept /User/ and /User/213123 Where 213123 is a parameter (user_id) Here is my RouteConfig.cs : routes.MapRoute( name: "user", url: "{controller}/{action}/{username}", defaults: new { controller = "User", action = "Index", username = UrlParameter.Optional } ); And my UserController.cs : public ActionResult Index() { ViewData["Message"] = "user index"; return View(); } [Route("user/{username}")] public ActionResult Index(string username) { ViewData["Message"] = "!" + username + "!";

what are the circumstances of using .Wait() when calling async methods

六月ゝ 毕业季﹏ 提交于 2019-12-10 11:22:46
问题 I have the following async long running method inside my asp.net mvc-5 web application :- public async Task<ScanResult> ScanAsync(string FQDN) { // sample of the operation i am doing var c = await context.SingleOrDefaultAsync(a=>a.id == 1); var list = await context.Employees.ToListAsync(); await context.SaveChangesAsync(); //etc.. } and i am using Hangfire tool which support running background jobs to call this async method on timely basis, but un-fortuntly the hangefire tool does not support

Create a complex type model validation attribute with server and client validation

前提是你 提交于 2019-12-10 10:59:05
问题 I'm trying to create an attribute that can validate a complex type both on the server and client side. This attribute will be used for required and non required complex types such as the following Address Class public partial class AddressViewModel { [DisplayName("Address 1")] [MaxLength(100)] public virtual string Address1 { get; set; } [DisplayName("Address 2")] [MaxLength(100)] public virtual string Address2 { get; set; } [MaxLength(100)] public virtual string City { get; set; } [MaxLength

How can I develop a custom AuthorizeAttribute that accepts a login OR a token?

匆匆过客 提交于 2019-12-10 10:56:21
问题 In my MVC 5 application, I decorate my controllers as follows: [Authorize] public class Controller { .. However, one requirement I have is to use a token to authorize an action without going to the login screen. ie: http://{website}/Action?token={/* token for this user */} Thus, how can I develop a custom AuthorizeAttribute that accepts a login (default behavior) OR a token (custom, required behavior)? In other words, if I use http://{website}/Action , I would be redirected to the login

Which NuGet package creates the web.config in your Views folder?

杀马特。学长 韩版系。学妹 提交于 2019-12-10 10:49:42
问题 My project is missing the web.config file from the Views folder. Here are the steps I took to make the project. Created an empty MVC project and installed the packages listed below. Created a controller and view. The view was created by right-clicking the action name and selecting 'Add View...' from the menu. Attempt to run the project, but got the error CS0103: The name 'ViewBag' does not exist in the current context I am getting this error because web.config is missing from my Views folder.

MVC5 Web app using ADFS On-Premises Organizational Auth and Visual Studio 2013 localhost development

两盒软妹~` 提交于 2019-12-10 10:38:01
问题 I am trying to create an MVC5 Web Application configured to use the On-Premises Organizational Authenticated Option (ADFS) as described Here by Vittorio Bertocci First, I create new MVC project. Then I change the Authentication to On-Premises. Set the On-Premises Authority to my ADFS federation metadata Endpoint. I checked to make sure the federation metadata xml could be reached and it was. I leave the App ID URI field blank accepting the default value. I ve done both, provided a value and

Custom Error pages in MVC 5

烈酒焚心 提交于 2019-12-10 10:37:32
问题 I have been trying to configure Custom Error pages in ASP.NET MVC 5 but with little complete success. To do this, I have followed this guide: http://benfoster.io/blog/aspnet-mvc-custom-error-pages Web.config customerrors <customErrors mode="On" defaultRedirect="~/500.aspx" redirectMode="ResponseRewrite"> <error statusCode="401" redirect="~/401.aspx" /> <error statusCode="403" redirect="~/401.aspx" /> <error statusCode="404" redirect="~/404.aspx" /> </customErrors> Web.config httpErrors

Entity Framework Seed not working

我的梦境 提交于 2019-12-10 09:51:41
问题 I have this on my web.config. <add name="AppDataContext" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\AppDatabase.mdf;Initial Catalog=AppDatabase;Integrated Security=True" providerName="System.Data.SqlClient" /> Global.asax APplication Start Database.SetInitializer<AppDataContext>(new AppDataContextInitializer()); AppDataContextInitializer.cs public class AppDataContextInitializer : System.Data.Entity.CreateDatabaseIfNotExists<AppDataContext> { protected

Sitecore, custom MVC controllers and routes

此生再无相见时 提交于 2019-12-10 09:46:07
问题 I have a website defined in Sitecore's site definitions. The path to it is /localhost/mysite/home . And it works. I need to create a custom controller to submit forms with an API bypassing Sitecore. So I have FormsController (inheriting from MVC controller) with an action named "Test" taking no parameters. I defined the route in the initialize pipeline like this: public class Initialize { public void Process(PipelineArgs args) { MapRoutes(); GlassMapperSc.Start(); } private void MapRoutes() {

POST to MVC controller IEnumerable nested Model is null when I don't select checkboxes in order

*爱你&永不变心* 提交于 2019-12-10 09:44:54
问题 When I'm trying to get values in Post the values of checkboxes are set to NULL when I don't check then in order (1, 2, 3, etc). I need to select any of them in no order (i.e. 4, 5). MODEL: public class AssignUsersViewModel { [Display(Name = "Check to select")] public bool Select { get; set; } public int Id { get; set; } [Display(Name = "App. Username")] public string UserName { get; set; } [Required] public string GivenName { get; set; } [Required] public string Surname { get; set; } [Display