Wednesday, October 13, 2010

ASP.NET Upload Error: Maximum request length exceeded

Add this to your web.config file.

<configuration>
<system.web>
<httpRuntime maxRequestLength="32768" />
</system.web>
</configuration>

Wednesday, March 24, 2010

SQL Server Network Service for ASP.NET User

if not exists (select * from master.dbo.syslogins where loginname = N'NT AUTHORITY\NETWORK SERVICE')
exec sp_grantlogin N'NT AUTHORITY\NETWORK SERVICE'
GO
exec sp_grantdbaccess N'NT AUTHORITY\NETWORK SERVICE', N'NT Authority\Network Service'
GO
exec sp_addrolemember N'db_owner', N'NT Authority\Network Service'
GO

Tuesday, March 23, 2010

WebDev.WebServer.Exe Stop has stopped working

Edit the solution file and find this:

VWDPort = "58332"

The assigned port here might be blocked so you have to
change the port to "8083"

Wednesday, October 28, 2009

Storing and Retrieving Cookies

Save Cookie


    private void StoreCookie(string visitorId, string visitorName)


    {


        HttpCookie cookie = new HttpCookie("VisitorInfo");


        cookie["VisitorId"] = visitorId;


        cookie["Name"] = visitorName;


        cookie.Expires = DateTime.Now.AddMinutes(3);


        Response.Cookies.Add(cookie);


    }





Retrieve Cookies


    private void RetrieveCookie()


    {


        var cookie = Request.Cookies.Get("VisitorInfo");


        var visitorId = cookie.Values["VisitorId"];


        var name = cookie.Values["Name"];


    }


Monday, October 26, 2009

Castle Windsor Simple Tutorial

Inversion of Control using Castle Windsor

1. Download Castle Windsor here

2. Add the following Libraries to your Project reference


 Castle.Core.dll


 Castle.DynamicProxy2.dll


 Castle.MicroKernel.dll


 Castle.Windsor.dll





3. Add the following to your Web Config


  <configSections>


    <section  name="castle"


             type="Castle.Windsor.Configuration.AppDomain.CastleSectionHandler, Castle.Windsor"/>


  </configSections>


 


  <castle>


    <components>


      <component id="castleTest"


                 service="MyAssembly.ICastleTest, MyAssembly"


                 type="MyAssembly.CastleTest, MyAssembly"/>


    </components>


  </castle>




4. Code implementation


public class CastleTest : ICastleTest


{


    #region ICastleTest Members


 


    public string HelloWorld(string text)


    {


        return "my test is " + text;


    }


 


    #endregion


}


 


public interface ICastleTest


{


    string HelloWorld(string text);


}




5. In your controller


    public ActionResult About()


    {


        WindsorContainer container = new WindsorContainer(new XmlInterpreter());


        ICastleTest service = container.Resolve<ICastleTest>("castleTest");


 


        ViewData["castleTest"] = service.HelloWorld("hello world");


 


        return View();


    }


Thursday, October 15, 2009

MVC Custom Route Problem on Scripts Path

If you encountered this error on your scripts
"A public action method 'Scripts' could not be found on controller"

It means that there is a problem mapping this files.

Since Custom routes changes the Path/Url, your views needs to be aware of this.

To avoid this problem you need to change the script url to this:
<script src="%3C%=%20Url.Content%28">" type="text/javascript"></script>
<script src="%3C%=%20Url.Content%28">" type="text/javascript"></script>
<script src="%3C%=%20Url.Content%28">" type="text/javascript"></script>

It will generate the correct path of your scrips

Tuesday, October 6, 2009

Creating a Custom Membership Provider

Here are the steps on how you can create your own membership provide in asp.net mvc framework:

1. First you need to create a class that inherits the abstract class MembershipProvider and implements all the abtract members.

public class CustomMembershipProvider : MembershipProvider

2. Override the function ValidateUser. Before you do this, I assume that you already created your database table.

 public override bool ValidateUser(string username, string password)
{
var user = (from u in _db.Users
where u.Username == username
&& u.Password == password
select u).SingleOrDefault();

if (user == null)
return false;
else
{
return true;
}
}


There are lot of procedures to override in the membership provider but I will let you do that with yourself.

3. Now, open your Web.Config and change the membership element to this:

<membership defaultprovider="CustomMembershipProvider">
<providers>
<clear/>
<add name="CustomMembershipProvider"
type="MVCApplication1.CustomMembershipProvider"
connectionStringName="ApplicationServices"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="true"
requiresUniqueEmail="false"
passwordFormat="Encrypted"
maxInvalidPasswordAttempts="5"
minRequiredPasswordLength="6"
minRequiredNonalphanumericCharacters="0"
passwordAttemptWindow="10"
passwordStrengthRegularExpression=""
applicationName="/" />
</providers>
</membership>


This are the settings for your membershipprovider.

THATS IT!
To test this you need to add dummy data to your users table.