서비스에 대한 액세스를 허용하는 clientaccesspolicy.xml 파일을 만듭니다. 다음 구성을 사용하면 다른 모든 도메인에서 현재 도메인의 모든 리소스에 액세스할 수 있습니다.

clientaccesspolicy.xml 
<?xml version="1.0" encoding="utf-8"?>
<access-policy>
  <cross-domain-access>
    <policy>
      <allow-from http-request-headers="*">
        <domain uri="*"/>
      </allow-from>
      <grant-to>
        <resource path="/" include-subpaths="true"/>
      </grant-to>
    </policy>
  </cross-domain-access>
</access-policy>
 
crossdomain.xml 파일을 사용하여 도메인 간 액세스를 허용하려면
<?xml version="1.0"?> <!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd"> <cross-domain-policy> <allow-http-request-headers-from domain="*" headers="*"/> </cross-domain-policy>
 --------------------------------------------------------------------------------------------------------------
 
 
접근하기 테스트
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO;
namespace SilverlightApplicationCardTest
{
    public partial class Page : UserControl
    {
        public Page()
        {
            InitializeComponent();
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            WebClient wc = new WebClient();
            wc.OpenReadCompleted += new OpenReadCompletedEventHandler(wc_OpenReadCompleted);
          //URL 여기에 clientaccesspolicy.xmlcrossdomain.xml 이 있어야 합니다

            wc.OpenReadAsync(new Uri("접근할려는 URL"));            
        }
        void wc_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
        {
            if (e.Error == null)
            {
                Stream responseStream = e.Result;
                // Continue working with responseStream here...
                StreamReader sr = new StreamReader(responseStream);
                this.txt.Text = sr.ReadLine();
            }
        }

    }
}

실버라이트 웹서버에서 작동안될때(MIME 형식 설정)

 

 

image

 

 

 

 

image

image




<html xmlns="http://www.w3.org/1999/xhtml" >

<head>

<title></title>

<script language="javascript">

// getPageSize() 메소드는 lightbox2.04 를 참고 하였습니다.

function getPageSize() {


var xScroll, yScroll;


if (window.innerHeight && window.scrollMaxY) {

xScroll = window.innerWidth + window.scrollMaxX;

yScroll = window.innerHeight + window.scrollMaxY;

} else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac

xScroll = document.body.scrollWidth;

yScroll = document.body.scrollHeight;

} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari

xScroll = document.body.offsetWidth;

yScroll = document.body.offsetHeight;

}


var windowWidth, windowHeight;


if (self.innerHeight) {



// all except Explorer

if (document.documentElement.clientWidth) {

windowWidth = document.documentElement.clientWidth;

} else {

windowWidth = self.innerWidth;

}

windowHeight = self.innerHeight;

} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode

windowWidth = document.documentElement.clientWidth;

windowHeight = document.documentElement.clientHeight;

} else if (document.body) { // other Explorers

windowWidth = document.body.clientWidth;

windowHeight = document.body.clientHeight;

}


// for small pages with total height less then height of the viewport

if (yScroll < windowHeight) {

pageHeight = windowHeight;

} else {

pageHeight = yScroll;

}


// for small pages with total width less then width of the viewport

if (xScroll < windowWidth) {

pageWidth = xScroll;

} else {

pageWidth = windowWidth;

}


return [pageWidth, pageHeight];

}







//리사이즈시 다시체크

function CheckTicket() {

//alert("리사이즈체크")

var arrayPageSize = getPageSize()

document.getElementById("overlay").style.width = arrayPageSize[0];

document.getElementById("overlay").style.height = arrayPageSize[1];

}







//덮기 테스트

function Test() {

var arrayPageSize = getPageSize()

document.getElementById("overlay").style.width = arrayPageSize[0];

document.getElementById("overlay").style.height = arrayPageSize[1];

}

window.onresize = CheckTicket //사용자가 윈도우 크기를 조정하면 다시 그사이즈에 맞게 덮어줍니다.

</script>


<!?아래는 반투명 스타일 시트-->

<style>


#overlay{

position:absolute ; left:0px; top:0px; width:10px; height:10px; z-index:100; filter:alpha(opacity=50);

background-color: #000;

}

</style>

</head>

<body onload="Test()">


<br />

전체화면 덮는 레이어 테스트<br />


<img src="image.jpg" style="width: 422px; height: 186px" />

<div id="overlay"> ß전체를 덮을 레이어

</div>


<p>

&nbsp;</p>

<p>

</p>


</body>

</html>

 

실버라이트 프로젝트에서 속성을 클릭합니다.

 image

 

실버라이트 프로젝트의 속성 선택

 image

브라우저 외부에서 응용 프로그램 실행사용 체크

 

이설정값들은

 image

OutOfBrowserSettings.xml에 저장됩니다.

설치옵션을 숨기려면 ShowInstallMenuItem 특성을 찾아 값을 "False"로 변경합니다.

 

실행결과

image

마우스오른쪽을 클릭하면 설치화면이 나옵니다.

 image

[외부에서 실행된 화면]

image

 

image

 

위와 같이 구성되어져 있을 때

UserInfo 에서 website에 있는 연결정보를 가져오기

 

 

 

1.

웹컨피그에서 접속정보가 아래와 같이 정의되어져 있습니다.

<connectionStrings>

<add name="ConnectionString1" connectionString="접속문자열"

providerName="System.Data.OracleClient" />

</connectionStrings>

 

2.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Web.Configuration;

 

namespace UserInfo

{

 

public class Class1

{

string _url;

public Class1() {

DbconnUrl = "클래스에서 가져오는 디비 정보:" + WebConfigurationManager.ConnectionStrings

["ConnectionString1"].ConnectionString;

 

}

public string DbconnUrl

{

 

set {

_url = value;

 

}

get {

 

return _url;

}

 

}

 

}

}

 

위와같이 가져옴 끗~

 

저장

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Configuration;

 

namespace WebApplicationTest

{

public partial class _Default : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

 

}

 

protected void Button1_Click(object sender, EventArgs e)

{

DataSet1TableAdapters.ImageTableTableAdapter adapter = new WebApplicationTest.DataSet1TableAdapters.ImageTableTableAdapter();

byte[] bt = this.FileUpload1.FileBytes; //이미지를 바이트로 저장하기

DataSet1.ImageTableDataTable dt = new DataSet1.ImageTableDataTable();

DataSet1.ImageTableRow row = dt.NewImageTableRow();

row.ImageContent = bt;

 

dt.AddImageTableRow(row);

adapter.Update(dt);

 

 

}

}

불러오기

InHandler.ashx 파일생성

<%@ WebHandler Language="C#" Class="InHandler" %>

  

using System;

using System.Web;

  

public class InHandler : IHttpHandler {

  

public void ProcessRequest (HttpContext context) {

  

가져오기 쿼리

  

System.Data.DataTable dt = op.GetDataTable(); //가져온 데이터

  

byte[] pic = (byte[])dt.Rows[0]["FILE_ATTACH"];//이미지를 저장하고 있는 필드

context.Response.OutputStream.Write(pic, 0, pic.Length);

context.Response.End();

}

  

public bool IsReusable {

get {

return true;

}

}

  

}

  

  

실제사용은 간단하게

<img src=" InHandler.ashx"> 이렇게 하면 끝~

URL: http://msdn.microsoft.com/ko-kr/library/system.data.oracleclient.oracletransaction.aspx

 


    using (OracleConnection connection = new OracleConnection(connectionString))
    {
        connection.Open();

        OracleCommand command = connection.CreateCommand();
        OracleTransaction transaction;

        // Start a local transaction
        transaction = connection.BeginTransaction(IsolationLevel.ReadCommitted);
        // Assign transaction object for a pending local transaction
        command.Transaction = transaction;

        try
        {
            command.CommandText =
                "INSERT INTO Dept (DeptNo, Dname, Loc) values (50, 'TECHNOLOGY', 'DENVER')";
            command.ExecuteNonQuery();
            command.CommandText =
                "INSERT INTO Dept (DeptNo, Dname, Loc) values (60, 'ENGINEERING', 'KANSAS CITY')";
            command.ExecuteNonQuery();
            transaction.Commit();
            Console.WriteLine("Both records are written to database.");
        }
        catch (Exception e)
        {
            transaction.Rollback();
            Console.WriteLine(e.ToString());
            Console.WriteLine("Neither record was written to database.");
        }
    }

JavaScript에서 관리 코드 호출

XAML 코드에 클라이언트 스크립트를 바인딩하려면

파일 위쪽에서 using 또는 Imports 문을 추가하여 System.Windows.Browser 네임스페이스를 가져옵니다.

// HtmlDocument requires using System.Windows.Browser;
HtmlDocument doc = HtmlPage.Document;
//Enable the HTML textbox on the page and say hello
doc.GetElementById("Text1").SetProperty("disabled", false);
doc.GetElementById("Text1").SetAttribute("value",   "This text set from managed code.");

(실버라이트에서 자바스크립트 호출)

aspx 페이지의 자바스크립트

<script>
    function TestBtn2(str) {
        slCtl.Content.mySLapp.Name = str;
    }
    function TestBtn() {

        alert(slCtl.Content.mySLapp.Name);
    }
</script>

실버라이트 cs 페이지

HtmlPage.Window.Invoke("Test", "");

또다른 방법

HtmlElement script = HtmlPage.Document.CreateElement("script");
script.SetAttribute("type", "text/javascript");
script.SetProperty("text", "alert('A')");
HtmlPage.Document.DocumentElement.AppendChild(script);

관리 코드에 대한 클라이언트 스크립트 액세스 테스트


image

실버라이트 페이지에 외부페이지와 스크립트 호출을 할수 있는 클래스를 만듭니다

using System.Windows.Browser;

namespace SilverlightApplicationCardTest
{
    public class MyScriptableManagedType
    {
        [ScriptableMember()]
        public string MyToUpper(string str) {
            return str.ToUpper();
        }

        [ScriptableMember()]
        public string Name { get; set; }
    }

}

 

 

App.xaml

페이지에서 외부에서 호출할 이름을 등록해줍니다

private void Application_Startup(object sender, StartupEventArgs e)
{
    this.RootVisual = new Page();

    //Set up some scriptable managed types for access from Javascript.
    MyScriptableManagedType smt = new MyScriptableManagedType();
    HtmlPage.RegisterScriptableObject("mySLapp", smt);

}

 

 

실버라이트가 포함된 페이지에서 처리부분

<script type="text/javascript" src="Silverlight.js"></script>
   <script type="text/javascript">
       var slCtl = null;

       function embedSilverlight(parentElement, pluginId, userContext) {
           var altHtml = pluginId == "sl1" ? null : "<!--not installed-->";
           return Silverlight.createObject("ClientBin/SilverlightApplicationCard.xap",
               parentElement, pluginId,
               {
                   width: "540", height: "340",
                   background: "white", alt: altHtml,
                   minRuntimeVersion: "2.0.30908.0", autoUpgrade: true
               },
               { onError: onSLError, onLoad: onSLLoad },
               "param1=value1,param2=value2", userContext);
       }

       function onSLLoad(plugIn, userContext, sender) {
           slCtl = sender.getHost();  //HTML 버젼

//// ASPX version
///slCtl = sender.get_element();


           alert(slCtl.Content.mySLapp.MyToUpper("Test String"));  //실제로 잘 불러와지는지 테스트

           window.status += plugIn.id + " loaded into " + userContext + ". ";
       }

       function onSLError(sender, args) {
           // Display error message.
       }
   </script>

 

</head>
<body style="height:100%;margin:0;">
    <form id="form1" runat="server" style="height:100%;">
        <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
        <div  id="sl2Host">
             <script type="text/javascript">
                 embedSilverlight(sl2Host, "sl2", "row2"); //실버라이트 바인딩
                </script>
        </div>

<input type="button"  onclick="TestBtn()" value="실버라이트 값 자겨오기" />
<input type="button"  onclick="TestBtn2('kojaedoo')" value="실버라이트 값 세팅하기" />


    </form>
</body>
</html>

페이지간 게시중 여러가지 중에서

2.0 에서는 Page.PreviousPage 속성이 있따

ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.ko/dv_aspnetcon/html/fedf234e-b7c4-4644-a9e8-c1c0870b043b.htm

간단한 사용법

a.aspx 의 TextBox1 컨트롤의 데이터 값을 b.aspx 에서 엑세스 할수 있다

a.aspx

<asp:TextBox ID="TextBox1" runat="server" Height="100px" TextMode="MultiLine"                                           Width="569px"></asp:TextBox>

<asp:ImageButton ID="ImageButtonFreeView" runat="server" PostBackUrl="Preview.aspx" />

 
b.aspx
if (Page.PreviousPage != null)
{
    TextBox SourceTextBox = 
        (TextBox)Page.PreviousPage.FindControl("TextBox1");
    if (SourceTextBox != null)
    {
        Label1.Text = SourceTextBox.Text;
    }
}

마스터 페이지 컨트롤에 접근할떄

ContentPlaceHolder 는 마스터페이지의 컨텐츠 영역입니다. 그 영역안에 있는 컨트롤 접근방법입니다 

if (PreviousPage != null && PreviousPage.IsCrossPagePostBack)
        {           
            if (PreviousPage.Master.FindControl("ContentPlaceHolder1") != null)
            {
                Response.Write(((TextBox)PreviousPage.Master.FindControl("ContentPlaceHolder1").FindControl("TextBoxMyEmail")).Text);
            }
        }
        else
        {
            Response.Write("Not a cross page postback");
        } 

+ Recent posts