Wednesday, September 08, 2010

Viewing Category


ASP.NET MVC

 

    30

    Dạo gần đây, mình có ngâm cứu phiên bản MVC của TheBeerHouse. Nó có 1 lỗi khi update role của 1 user. Giả sử một user có role A. Nó không có role B, C, D, E. Khi 1 admin vào edit user đó, check them role B cho user đó. Rồi click update. Lập tức các role khác đều được check cả.

    Thực sự không hiểu sao nhóm phát triển lại để lỗi đó xảy ra. Mình đã loay hoay tìm lỗi và ngồi sửa lại được. Đó là hàm EditUser trong UserController.cs. Và hàm được sửa lại như sau:

    [AcceptVerbs("POST")]

            public ActionResult EditUser(string id, bool approved)

            {

                //Is a list of all the user roles

                ArrayList removeRoleList = new ArrayList(Roles.GetAllRoles());

     

                //We are requesting the form variables directly from the form

                foreach (string key in Request.Form.Keys)

                {

                    if (key.StartsWith("role."))

                    {

                        String userRole = key.Substring(5, key.Length - 5);

                                           

                        if (Request.Form[key] == "true" || Request.Form[key] == "true,false")

                        {

                            removeRoleList.Remove(userRole);

                            if (!Roles.IsUserInRole(id, userRole))

                            {

    [Read the rest of this article...]

    Posted in: ASP.NET MVC
    21
    Posted in: ASP.NET MVC
    08

    Mấy hôm nay, mình đang nghiên cứu thử ASP.NET MVC. Và đang chạy thử site TheBeerHouse. Để chạy thử nó, mình đã cài SQL Server 2005 bằng cách chạy script lấy từ site của nó. Web.config đã được chỉnh sửa lại.

    <add name="TheBeerHouseConnectionString" connectionString="Data Source=ABC;Initial Catalog=TheBeerHouse;User ID=sa;Password=xxx" providerName="System.Data.SqlClient"/>

    Chạy thử thì thấy mọi chuyện có vẻ ok. Tuy nhiên, đến khi view trang User/UserProfile thì bị báo lỗi.

    A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    [Read the rest of this article...]

    Posted in: ASP.NET MVC
    HomeTrangITForum
    Copyright 2010 by Nguyễn Minh ĐứcDesigned by DyNNamiteTerms Of UsePrivacy Statement