System.Web.Mvc.HttpPostAttribute vs System.Web.Http.HttpPostAttribute? [duplicate] - c#

This question already has answers here:
What is the different between System.Web.Http.HttpPut Vs System.Web.Mvc.HttpPut
(2 answers)
Closed 3 years ago.
In my Web API project which is based on the ASP.NET MVC, I want to use the HttpPost attribute. When I've added that onto the action, The IntelliSense suggests me these two namespaces:
System.Web.Mvc.HttpPostAttribute
System.Web.Http.HttpPostAttribute
Which one should be used and why?

Prior to ASP.NET Core, MVC and WebAPI were mainly separate libraries.
The .Mvc namespace applies to MVC controllers, the .Http namespace to Web API controllers.

Related

How to access EFCore context after initiating .Net Core API? [duplicate]

This question already has answers here:
Get a service in a IServiceCollection extension
(1 answer)
How should I use appsettings.json config key/values in my ConfigurationServices ASP.NET Core 2.0 on startup?
(2 answers)
Closed 5 years ago.
I'm in need to Access the EFCore Context after initiating or starting the API.
I wan't to load some Settings from my Database to configure some Services.
It would be good to load this settings just one time so like loading it in a Singleton Service which holds and provides them after that.
I can't find a good solution to just use the Context after the Startup of the API.
A simple solution would be great just something like this (If this is even possible somehow):
BuildWebHost(args).Run();
// I wan't to call the function something like this after starting/running/iniating the api
AppSettingsManager.LoadSettings(MyContext);
Would be great if someone can tell me how to achieve this or show me a Post, Blog or what ever that explains how to do this.

How to render partialView from another application? [duplicate]

This question already has answers here:
MVC Rendering (RenderPartial, RenderAction) Html from another MVC Application
(2 answers)
Closed 5 years ago.
I have 2 applications published in the same site in iis, so the only diference between both is the virtual path, ex: localhost:2020/app1 and localhost:2020/app2. My problem is that in the app1, I want to call a partialView from the app2 and I can't add the references from the app2 to the app1. Any idea how to do that?
The only reasonable way (to me at least) to do this is to move shared partial views to separate library and use RazorGenerator tool to generate code for them. Then when you will reference the library in web projects of both applications those views will be available to use.

Render view as string in MVC 6 [duplicate]

This question already has answers here:
Render Razor view to string in ASP.NET 5
(2 answers)
Closed 7 years ago.
After a long search for a solution to this problem, I only found MVC5 and outdated solutions.
Now that we are in asp.net 5 beta 7, there are any way to render a view to a string variable ?
I need to render a view to show it in a bootbox javascript control (like a modal windows).
The MVC 5 solutions does not work in version 6 because there is no "ViewEngine" class in there. Look:
and even the Razor object canĀ“t be found:
You can use this approach (see RenderPartialViewToString):
https://stackoverflow.com/a/32577016/2631076

How to check from which action I came in asp.net mvc [duplicate]

This question already has answers here:
How do I get the referrer URL in an ASP.NET MVC action?
(4 answers)
Closed 8 years ago.
I have asp.net mvc 4 application, where I need to do some action when I came from HomeController ActionResult DoSmth(). How can I check this?
I use
Request.UrlRefferer
To do this.
You can use the following
var controller = (string)this.RouteData.Values["controller"];
var action = (string)this.RouteData.Values["action"];
Not sure if relevant, but if you want to make sure that action is rendered only from your code you can use attribute [ChildActtion].
Otherwise check this answer: ASP.NET MVC - Check if request comes from another action

URL Rewriting in ASP.NET 4.0 [duplicate]

This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
ASP.NET 4.0 URL Rewriting: How to deal with the IDs
I am trying to do url re-writing in my asp.net c# project, and I searched internet but did not get what I was looking for.
Say, for example I have following url:
http://www.example.com/Question.aspx?qid=1
Now, Question.aspx finds a question against (which has title and body field) for qid from the db and displays it. I want to display question title in url.
My requirement is something like this:
http://www.example.com/Question/1/QuestionTitleGoesHere
Can anyone please suggest that how can I achieve this ASP.NET 4.0?
You can check following working examples of URL Rewriting in asp.net web forms projects using
URL Rewriting using ASP.NET for SEO
Tip/Trick: Url Rewriting with ASP.NET
In IIS you can use Url Rewrite to achieve this.
If you need this to be within the application, could you look at using MVC3/MVC4 instead of webforms? If that is an option.
I think you should try these links:
URL Routing with ASP.NET 4 Web Forms (VS 2010 and .NET 4.0 Series)
ASP.NET Routing
They will help you.

Categories