What Folder To Put Site-wide Functions/classes In .NET MVC
Mar 22, 2010
I'm new to ASP.NET MVC and i want to create a class to contain site wide functions for my application.what is the best practice to do this?
where should i create the class ? in what folder?should i create a new folder?
edited:I need a function that return base uri, and it have be available to call from any controller.A date formatting function, or any other simple logic , but is going to be used repetitively
View 2 Replies
Similar Messages:
Feb 16, 2010
I have an application in which a user can choose from different (learning)groups. User has only access to registered groups. When the user enters the site, he can choose (in a dropdown) which group he wants to see, so the complete site filters content related to that group. So every controller needs to access this global "group" object.What is the best way to do this in ASP.NET MVC? I've thought about a BaseController or ActionFilters. Is there any other best practice?I've build a WebForms application and there I used a BasePage so that any other page has access to the group.
View 2 Replies
Oct 4, 2010
I have some code in my new asp.net app that I need to share. So i created a shared class called
"utilities.vb" and put it in the APP_CODE folder. There is a function I have in there that pulls a person's image based off of their MemberId.
[Code]....
And I can call this function from my page using utilities.FcnGetMemberImage(). Ok, so all good so far until it complains about...
"Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class"
when referring to the Server.MapPath()
But the problem is that if I don't make it a Shared Function, I can't access it from my other pages. But if I do make it a Shared Function, it throws this error. The fix is supposed to be that I either don't share the function, or
"add the shared keyword to the member declaration", according to Microsoft at
http://msdn.microsoft.com/en-us/library/xfsswe45.aspx
But I'm not exactly sure how to "add the shared keyword to the member declaration" or what this means exactly and how this might affect other parts of my code?
Or is there a better way to work around this dilemma?
View 3 Replies
Aug 16, 2010
I'm building a web app that will keep a events in a database and add the event to a Google calendar on insertion.
I have three types of events, PendingEvents, ApprovedEvents, and DeniedEvents. I'm using single table inheritance through LINQ-to-SQL, with the Event class being abstract and the 3 types inheriting from it
Each type of Event is stored in calendars differently. I would like to use an abstract member function in Event called AddToCalendar.
I'm trying to set this up in a separate class file because I'm using the LINQ-to-SQL designer and I don't want these to be overwritten if I change the LINQ diagram.
However, I get an error from all three inherited classes that "'WebCal.ApprovedEvents' does not implement inherited abstract member 'Edu.Northwestern.WebCal.Event.AddEventToCalendar()' WebCalendarWebApplication1App_CodeWebCalDataSource.designer.cs"
It looks like it won't check my outside file and only looks at the designer.
The non-designer partial class file looks something like this:
public partial class WebCalDataSourceDataContext : System.Data.Linq.DataContext
{
View 2 Replies
Apr 15, 2010
can I change an aspx file name site wide. i.e. every instant of it any where in the site?
View 4 Replies
May 27, 2010
I wanted to use some javascript functions in a ASP.net 3.5 web site. I have added a javascript1.js page in the Sites Folder with a Javascript Test function.
<script
src="~/Scripts/Javascript1.js"
type="text/javascript"></script>
View 4 Replies
Sep 17, 2010
Using vb.net/asp.net 2005. I have a project that is done with all vb.net, however I want to get some more experience with C#.Net. I am considering creating a new database class to put in the app_code folder.
View 3 Replies
Aug 10, 2010
I have an application which contains different modules from different databases, for instance, I have a table called "ITEMS" in each database. When I create the classes for the table ITEMS I wonder how I can differentiate among them.
For instance, for now, I have "ItemDetails.cs" under App_Code folder BUT I need to create another "ItemDetails.cs" class which will reference the table ITEMS from a different database. If I create folder under the App_code the class name still remains the same.
I could add an acronym in front the class to differentiate which database I am working from but that makes the class name too long.
View 2 Replies
Apr 27, 2010
I have a single project. and I have two folder in it. In the 1st folder I have a class named Class1 and in the 2nd folder I have a class named Class2. Can anyone tell me how I can access members of Class1 in Class2. I have tried by adding namespace in Class1 and Using that namespace in Class2. But it is giving error. It is easy to access classes or their members from App_Code folder. I don't want to put my classes in app_code folder.
View 5 Replies
Jan 7, 2011
I've searched but not found much that helps, could be using wrong search terms.Anyway, currently using Visual Studio 2005 and VB, but just got Visual Studio 2010 and trying to use C# and am having problems using classes, I think I'm missing something simple here.
In both 2005 & 2010 I create a new website and a Default.aspx, in 2005 using VB, C# in 2010.
Right-click the project -> Add New Item -> Class, and leave it as Class1.vb/Class1.cs
Both 2005 & 2010 prompt to place it in the App_Code folder, so choose yes.
Here are the class files, I've not changed anything apart from create a very simple function:
Class1.vb code: [Code]....
Class1.cs code: [Code]....
In my VB project Default.aspx.vb: [Code]....
No errors, and debugging shows that a = "hello"
My Default.aspx.cs: [Code]....
This gives an error:Error 1 The name 'tester' does not exist in the current context D:Visual Studio 2010WebSite11Default.aspx.cs
How do I reference the tester function within Class1 in my C# project?
View 4 Replies
May 28, 2010
How can I prevent Visual Studio from naming the classes for new pages that are in folders from being named with the folder name? Does this method not set "right" with anyone else?
View 1 Replies
Aug 5, 2010
I am fairly new to ASP.net and web page development. I normally create Windows Apps, but the move is on to web pages. I have read and tried a number of posts on this matter, but none of them resolved the problem I am having. I have created a web site (I'm positive it is a web site) and added a class. Visual Studio automatically created and added the class to the App_Code folder. Accordingly, I added the get/set methods to the class and made them public. When ever I try to access the class from a code behind for any page, I get the class name, but nothing more. Intellisense shows only Equals and EqualsReference - no variables. I'm used to using classes in windows forms application and this would make life so much easier if it worked like it is supposed to work.
View 2 Replies
Feb 7, 2011
Environment: Windows 2008 R2 x64 [IIS7.5]
irectoryInfo("D:MySecretFolder")
I get thrown the following error.
'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed
Application pool is using NetworkService account as its identity and I have given that account full rights on that folder.
View 2 Replies
Jan 26, 2011
I have a .net website that I've built but here's the catch - when it's deployed I don't know whether it will be deployed to the root of the site or to a sub folder of a larger site (and it needs to be able to move around between places)
And - here's the important bit - we will have zero access to IIS on the live server so this just has to run straight away.
So far I've managed to find work arounds for things like paths to resources but I now need to use a 3rd party component (.dll).
Normally this would go in the bin folder and, if I run my site in the root of the website it works fine but, as soon as we move the site to a sub folder, the reference to the 3rd party component wont work.
Now - I know normally you'd suggest creating a virtual directory under IIS but remember - I HAVE NO ACCESS TO IIS.
So - is there a way to still use 3rd party components in my project and have my project all run in a sub folder of a website?
And no - I can't move just the bin folder to the root of the site - it all has to sit within its own folder.
View 2 Replies
Jan 11, 2010
I am new to LINQ. when we drag tables we get a dbml file and designer file.
For example DataClasses1.dbml and DataClasses1.designer.cs.
Once we have them then we can start using our LINQ Queries.
In my company project I do not see this designer files and instead there are .tt files which were used as templates to greate ABC.generated.cs files. Is this same as designer class?
View 3 Replies
Apr 23, 2010
I develop a simple file manager inside an ASP.NET Web site (not web application). I notice that every time I rename or delete a folder, the site gets recompiled - i.e. the very next web request after delete or rename operation takes considerably much time to execute.
It's only true for folders, not for files.Why does this occur?
P.S. I use WebDev server (Cassini), haven't tested in on IIS yet.
UPDATE: The same disaster happens with ASP.NET MVC Web Applications :(
UPDATE 2: Here are similar discussions:
http://stackoverflow.com/questions/271944/storing-temporary-user-files-in-aspnet-in-medium-trust
http://stackoverflow.com/questions/2248825/asp-net-restarts-when-a-folder-is-created-renamed-or-deleted
View 2 Replies
Mar 14, 2011
i am sending mails in asp.net via my hos eHostPros.but recepients receive main inside their junk folder.
View 4 Replies
May 17, 2010
I am following the Nerd Dinner tutorial as I'm learning ASP.NET MVC, and I am currently on Step 3: Building the Model. One part of this section discusses how to integrate validation and business rule logic with the model classes. All this makes perfect sense. However, in the case of this source code, the author only validates one class: Dinner.
What I am wondering is, say I have multiple classes that need validation (Dinner, Guest, etc). It doesn't seem smart to me to repeatedly write these two methods in the partial class:
[code]....
This doesn't "feel" right, but I wanted to check with SO to get opinions of individuals smarter than me on this. I also tested it out, and it seems that the partial keyword on the OnValidate method is causing problems (understandably so). This doesn't seem possible to fix (but I could very well be wrong).
View 1 Replies
Aug 11, 2010
I don't know if this has to do with how FindControl works or how scope works. But my base class is having a hard time seeing the fields of child classes. Currently I'm planning have the derived class set a property in the base class, but there are a lot of derived classes, so that isn't a very attractive solution.
[code]....
View 4 Replies
Aug 18, 2010
I've got webform routing setup on my asp.net webforms 3.5sp1 project. I would like to have the files for the site in a directory called content including the home page as I would like to run multiple sites using the same system. In MVC there is a blank default page and the home page is in a folder called home. I can't seem to replicate this behaviour using web form routing but would like to. The blank page is always hit first. the route handler is hit second - it recognises that the request is for the home page and sets up the routing page but is not used. the route handler code is simple:
public string VirtualPath { get; private set; }
public IHttpHandler GetHttpHandler(RequestContext
requestContext)
{
string file = requestContext.RouteData.GetRequiredString("File");
string id = requestContext.RouteData.GetRequiredString("Id");
string queryString = "?menuid=" + id;
VirtualPath = "~/" + file;
HttpContext.Current.RewritePath(
string.Concat(
VirtualPath,
queryString));
var page = BuildManager.CreateInstanceFromVirtualPath
(VirtualPath, typeof(Page)) as IHttpHandler;
return page;
}
Is there anyway I can do this?
Update
Here is my global.asax route code:
public static void RegisterRoutes(RouteCollection routes)
{
Domain.RepositoryFactory repo = new RepositoryFactory();
foreach (var x in repo.MenuRepository.GetAllEnabledGetMenus())
{
if (string.IsNullOrEmpty(x.Url))
{
//add default
System.Web.Routing.RouteTable.Routes.Add(
new Route("Default.aspx",
new RouteValueDictionary(new { File = x.FileName,
Id = x.Id.ToString() }),
new CoreRouteHandler()));
}
else
{
string url = x.Url;
if(x.Url.StartsWith("/"))
{
url = url.Remove(0, 1);
}
System.Web.Routing.RouteTable.Routes.Add(
new System.Web.Routing.Route(url,
new RouteValueDictionary(new {File = x.FileName,
Id = x.Id.ToString()}),
new CoreRouteHandler()));
}
}
}
View 2 Replies
Mar 8, 2011
I have my main web site pages in the Root folder. I have several other pages in a subfolder below the Root folder. When I launch a web page that is in the sub folder it does not correctly render the page. For example it loses the gif image that needs to be on every page. Is there something I need to add to the pages in the sub folder or do I need to set the path differently to the master page? Currently it looks like this;
[Code]....
This works for the web pages in the Root folder.
View 6 Replies
Nov 30, 2010
I don't know much about the .Net environment, so my first idea was to just write a console app that scans the folder for new content, and then emails alerts out. Then put the .exe as a scheduled task on the server, executing every few minutes. This seems pretty archaic to me though. Is there a more elegant way to do this for my website?
View 3 Replies
Mar 24, 2010
Can I use VB and C# classes together in the same asp.net 3.5 project?
View 3 Replies
Dec 15, 2010
I'm curious as to what people consider better practice, between duplicating model structure in the view model and using a mapping tool to move data between the two, or aggregate the model inside the view model, i.e. have a property on the view model class that is a reference to the actual model. Which is considered a better approach in general?
View 1 Replies
Apr 5, 2010
I want a separate config file (not app.config) that stores style for various controls in my web application. For example i want to specify the CSS file that modifies all instances of GridView in the website. what is best practice?
View 2 Replies