What are the advantages and disadvantages if I make my web api controller inherit from MvcController class instead of ApiController class?
If your Controller inherits from MvcController class it won't be an API Service , It'll become an MvcController that need view and will be displayed in Html Page .
Related
I need some logic to be executed before action execution. The problem is that I have both ApiController and Controller classes.
I've tried to use common for both System.Attribute but override Match() will not execute. Any Ideas ?
I have an asp.net website with individual .aspx files which all inherit my Custom Class. There are common features to each .aspx page such as menus and things like that. So I have created a Master Page.
I want to put the common methods which call methods from my custom class in my master page code behind and I cannot. As I don't seem to be able to get my Master Page to inherit from it.
I want to change the following..
Partial Class modules_MyPage
Inherits System.Web.UI.MasterPage
To something like this...
Partial Class modules_MyPage
Inherits MyCustomClass
The above damages my content pages. I was wondering if anyone could advise me on the right approach.
What you want is something like this:
Partial Class modules_MyPage Inherits MyCustomClass
where
Partial Class MyCustomClass Inherits System.Web.UI.MasterPage
but this isn't possible if your class already inherit from web.ui.Page
really usefull article
I have created a class in asp.net and I want to inherit the Main Page. I have tried below but it has an error:
Public Class Class1
Inherits Main Page
End Class
In windows Application inheriting form is much easier than in asp.net. Just like below:
Public Class Class1
Inherits FormMain
End Class
Can someone help me on inheriting page in a class?
Thanks in advance.
Your class name must be a single word. Try Main_Page or MainPage since in many cases the underscore character is hidden by other elements or the cursor.
Otherwise, search you project for the class and make sure you are using the same name as the actual implementation of the class.
This is probably not something you want to really do. The web page in ASP.NET WebForms consists of two parts - Design and Code-behind. The design part is translated into rendering Visual Basic code during compilation.
I can't see a reason for deriving from a WebForms page. What are you trying to achieve? You can certainly change the base class the page uses, but there is practically no logical reason to derive from it.
EDIT:
You might be actually trying to do something in the sense of having a base page and then other pages that have the same basic "structure". That is possible, but using a different ASP.NET mechanism called MasterPages (http://msdn.microsoft.com/en-us/library/wtxbf3hh.ASPX)
Assuming your MainPage is your inheriting class, then make sure it's declared something like:
''' <summary>
''' Base page for all other web pages in the system.
''' </summary>
Public Class MainPage
Inherits Page
...
End Class
Your ASP.NET class would then be:
Public Class Class1
Inherits MainPage
...
End Class
When implementing authorization for ASP.NET, where should I put AuthorizeAttribute implemented class?
In my project, I have created a class called BasicHttpAuthorizedAttribute which implements System.Web.Http.AuthorizeAttribute class and I have overridden the methods I want.
I have registered this BasicHttpAuthorizedAttribute class as a filter.
My problem is even though I do not mention the [Authorized] attribute on top of controller method, BasicHttpAuthorizedAttribute class's OnAuthorization() method gets called.
That should not be like that, right? It should only be called if you have mentioned [Authorized] attribute on top of controller method. Am I right?
What am I doing wrong here? (My project is a ASP.Net web api project and I am using System.Web.Http.AuthorizeAttribute class)
Basically, it goes into the OnAuthorization() event each time because you've registered it as a filter.
This article has a few neat tips and trips on blanket filtering and anonymous exceptions, which is, I think, what you want. It may be for MVC, but the techniques used should apply to most ASP.NET types with a little tweaking.
http://blogs.msdn.com/b/rickandy/archive/2011/05/02/securing-your-asp-net-mvc-3-application.aspx
Example from article:
[HttpPost]
[AllowAnonymous]
public ActionResult LogOn(LogOnModel model, string returnUrl)
I'm trying to use a Model with my Asp.net page. But im not using MVC. I get an error when trying to inherit the model from a customcontrol. The error is
ViewModel: interface name expected.
public partial class CustomControl : UserControl, ViewModel
You cant do multiple inheritance in C#. UserControl and ViewModel are both classes and you are only able to inherit from a single class.
You can however implement as many interfaces as you like.